package mlz.a_stram;

import java.security.Key;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Stream;

/*
Stream流的创建方式
- 集合获取流
  - Collection: 都有`stream()`
  - Map: 借助Collection集合中的`stream()`方法
- 数组获取流: `Stream.of(数组名)`

 */
public class StreamDemo02 {
    public static void main(String[] args) {
        //1.单列集合: Collection (List\Set)
        //List -> of是JDK9版本新增的添加方法
        List<String> list = List.of("喜洋洋", "美羊羊", "沸羊羊", "懒洋洋");
        //创建list集合的流对象
        Stream<String> stream = list.stream();

        //Set集合
        Set<String> set = Set.of("喜洋洋", "美羊羊", "沸羊羊", "懒洋洋");
        Stream<String> stream1 = set.stream();

        //2.双列集合 -> map
        Map<Integer, String> map = Map.of(1, "张三", 2, "李四", 3, "王五");
        //map集合本身是不能进行遍历的,但是可以借助map集合中提供的方法获取到对应的Collection集合然后再进行遍历

        //获取map集合中的key
        Set<Integer> keySet = map.keySet();
        Stream<Integer> stream2 = keySet.stream();

        //获取map集合中entry -> 封装到一个set集合中
        Set<Map.Entry<Integer, String>> entries = map.entrySet();
        Stream<Map.Entry<Integer, String>> stream3 = entries.stream();


        //3.数组
        Stream<Integer> stream4 = Stream.of(1, 2, 3, 4, 4);
    }
}
























